package com.hby.game

import android.app.Activity
import android.widget.TextView
import com.business.Analyse
import com.business.AnalyseKey
import com.helloandroid.AppUtil
import com.helloandroid.MyApplication
import com.helloandroid.R
import com.helloandroid.ads.NativeAdUtil
import com.helloandroid.ads.VideoAdUtil
import com.helloandroid.base.BaseDialog

class HbyExitDialog(val activity: Activity,val coin:Int) : BaseDialog(activity) {

    lateinit var tvCoin:TextView

    override fun getContentViewResId(): Int = R.layout.dialog_hby_exit

    override fun initView() {
        tvCoin = findViewById(R.id.tvCoin)
        tvCoin.text = "x$coin"

        AppUtil.appViewModel().hbyAward(coin)
        findBtn(R.id.btnClose).setOnClickListener {
            closeAndExit()
        }
        findBtn(R.id.btnDouble).setOnClickListener {
            VideoAdUtil.playVideoAd(activity) { success: Boolean ->
                if (success) {
                    Analyse.report(AnalyseKey.Hby_Video)
                    AppUtil.toast("恭喜获得${coin}额外奖励!")
                    AppUtil.appViewModel().doubleAward(coin)
                    closeAndExit()
                } else {
                    AppUtil.toast("视频加载失败,请稍后再试!")
                }
            }
        }

        // 显示 广告
        NativeAdUtil.showNativeAd(activity,findViewById(R.id.nativeView))
    }

    override fun initData() {
    }

    private fun closeAndExit(){
        dismiss()
        activity.finish()
    }
}